<template>
  <div class="main" v-color="'bgkImg'">
    <dz-nav :is-back="true" :back-url="-1">
      <template #center>
        <b v-color><qq>Recharge</qq></b>
      </template>
    </dz-nav>

    <div class="center-box">
      <div class="img-box">
        <canvas style="width: 220px;height: 220px" ref="qrcodeCanvas"></canvas>
        <p><van-count-down :time="time" /></p>
        <div class="content">
         <qq>tip1</qq>
        </div>
      </div>
    </div>
    <div class="bottom-box">
      <div class="center">
        <div class="item">
          <span><qq>TransferNetwork</qq>：</span>
          <b>{{ formData.coinCode }}</b>
        </div>
        <div class="item">
          <span><qq>DepositAmount</qq>：</span>
          <b>{{ formData.amount }} USDT</b>
        </div>
      </div>
      <div class="item-url">
        <span>{{formData.address}}</span>
        <b><img @click="oncopy(formData.address)" src="@/assets/images/btn-link.png" alt=""></b>
      </div>
    </div>
    <dz-safe></dz-safe>
  </div>
</template>

<script>
  import {getSessionItem} from "@/utils/auth";
  import {Toast} from "vant";
  import QRCode from "qrcode";

  export default {
    data(){
      return{
        time:7200000,
        formData:{}
      }
    },
    methods:{
      getList(){
        let form = getSessionItem('pay')
        this.formData = form
        this.generateQRCode()
      },
      generateQRCode() {
        const canvas = this.$refs.qrcodeCanvas
        QRCode.toCanvas(canvas, this.formData.payUrl, error => {
          if (error) console.error(error)
        })
      },
      oncopy(code){
        this.$copyText(code).then(
            e=>{
              Toast({
                position:'center',
                message:this.$t('Success')
              })
            },
            e=>{
              console.log('error：', e);
            }
        )
      },
    },

    mounted() {
      this.getList()
    }
  }
</script>

<style scoped lang="scss">
  .main{
    width: 100%;
    min-height: 100vh;
    .center-box{
      width: 100%;
      min-height: 280px;
      margin-top: 50px;
      display: flex;
      justify-content: center;
      align-items: center;
      .img-box{
        width:260px;
        min-height: 280px;
        background: #fff;
        border-radius: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        padding: 20px 0 20px 0;
        img{
          width: 200px;
          height: 200px;
          border-radius: 10px;
        }
        p{
          width: 100%;
          margin: 10px 0;
          text-align: center;
        }
        .content{
          width: 100%;
          font-size: 14px;
          color: #666666;
          padding: 0 15px;
          box-sizing: border-box;
        }
      }
    }
    .bottom-box{
      width: 100%;
      min-height: 100px;
      margin-top: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: wrap;
      .center{
        width: 350px;
        padding: 20px;
        box-sizing: border-box;
        background: #fff;
        border-radius: 10px;
        .item{
          width: 100%;
          display: flex;
          justify-content: space-between;
          align-items: center;
          border-bottom: 1px solid #f9f9f9;
          padding: 10px 0 6px 0;
          span{
            width: 50%;
            font-size: 14px;
          }
          b{
            font-size: 16px;
            img{
              width: 22px;
              height: 22px;
            }
          }
        }
      }
      .item-url{
        width: 350px;
        font-size: 14px;
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 10px;
        box-sizing: border-box;
        img{
          width: 22px;
          height: 22px;
        }
      }
    }
  }
</style>